import Car from "../motorcade-car/car";
import Icons from '_c/icons'
import {
  getAllDepartment_,
  getAllRole_,
  getEmployeeInfoByAccount, getRolePermission,
  getRolePersonnelList,
  getTeamPersonnel, updateEmployee, updateEmployeeRole, updateRolePermission
} from "../../../api/data";

export default {
  name: "motorcade-role-permission",
  components: {
    Car,
    Icons

  },
  data() {
    return {
      modal1:false,
      roleQuery: {
        department: '1001',
        role:'全部',
        status: '1',
        page: '1',
        limit: '10',
      },
      roleQuery2: {
        role: '1',
        permission: []
      },
      formItem:{
        account: '',
        uroleId: '',

      },
      roles:[],
      permission:[],
      theme3: 'light',
      loading: false,
      indeterminate: true,
      checkAll: false,
      checkAllGroup: [],
      columns1: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '部门',
          key: 'corganName',
          align: 'center'
        },
        {
          title: '姓名',
          key: 'name',
          align: 'center'
        },
        {
          title: '职位',
          key: 'uroleName',
          align: 'center'
        },
        {
          title: '电话',
          key: 'phone',
          align: 'center'
        },
        {
          title: '操作',
          slot: 'operation',
          width: 200,
          align: 'center'
        }
      ],
      data1: [
      ],
      organizations: [],
      statusList: [
        {
          label: '正常',
          value: 1
        },
        {
          label: '停用',
          value: 0
        }
      ]
    }
  },
  methods: {
    changePage(pageNumber) {
      this.roleQuery.page = pageNumber
      this.queryList()
    },
    changeSize(pageSize) {
      this.roleQuery.limit = pageSize
    },
    queryList() {
      getRolePersonnelList(this.roleQuery).then(res => {
        this.data1 = res.data.obj;
      }).catch(err => {
        alert(err.data.message)
      })
      console.log(this.data1)
    },
    handleCheckAll() {
      if (this.indeterminate) {
        this.checkAll = false;
      } else {
        this.checkAll = !this.checkAll;
      }
      this.indeterminate = false;
      if (this.checkAll) {
        this.checkAllGroup = ['查看列表', '查看详情', '停用','新建员工', '编辑', '禁止登陆','恢复', '允许登陆', '重置密码',];
      } else {
        this.checkAllGroup = [];
      }
    },
    checkAllGroupChange() {
      updateRolePermission(this.roleQuery2).then(res=>{
        this.$Message.info(res.data.message);
      }).catch(err=>{
        alert(err.data.message)
      })
    },
    selectMenu() {
      if (arguments[0]=="1"){
        this.roleQuery.role='系统管理员';
      }else if(arguments[0]=="2"){
        this.roleQuery.role='一级管理员';
      }else if(arguments[0]=="3"){
        this.roleQuery.role='二级管理员';
      }else if(arguments[0]=="4"){
        this.roleQuery.role='三级管理员';
      }else if(arguments[0]=="5"){
        this.roleQuery.role='驾驶员';
      }else{
        this.roleQuery.role='全部';
      }
    },
    selectMenu2() {
      this.roleQuery2.role=arguments[0]
      getRolePermission(this.roleQuery2).then(res => {
        this.roleQuery2.permission=res.data.obj
      })
    },
    getAllDepartment() {
      getAllDepartment_().then(res => {
        this.organizations = res.data.obj;
      }).catch(err => {
        alert(err.data.message)
      })
    },
    getAllRole(){
      getAllRole_().then(res=>{
        this.roles=res.data.obj;
      }).catch(err=>{
        alert(err.data.message)
      })
    },
    editItem(index){
      console.log(this.data1[index])
      this.formItem.account=this.data1[index].account
      this.formItem.uroleId=this.data1[index].uroleId
      this.modal1=true;
    },
    submit(){
      updateEmployeeRole(this.formItem).then(res=>{
        if (res.data.code==500){
          this.$Message.info(res.data.message);
        }else{
          this.$Message.info("添加成功");
          this.modal1=false;
          this.queryList()
        }
      }).catch(err=>{
      })
    },
    resetForm(){
      this.modal1=false
    },
  },
  mounted() {
    this.getAllDepartment()
    this.queryList()
    this.getAllRole()
    getRolePermission(this.roleQuery2).then(res => {
      this.roleQuery2.permission=res.data.obj
    })
  }
}
